home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Sherlock 2.0 / DevLibSrc / Main_DevLib / LIBtime.c < prev    next >
Text File  |  1995-11-07  |  2KB  |  76 lines

  1. /*
  2.     devlib: time routines
  3.  
  4.     Do not use Sherlock in this file.
  5.  
  6.     source:  LIBtime.c
  7.     started: November 6, 1995.
  8.     version: November 6, 1995.
  9. */
  10.  
  11. #if defined(THINK_C) || defined(applec) || defined(__MWERKS__)
  12.     #include <Errors.h>        /* For file errors. */
  13.     #include <OSUtils.h>    /* For SysBeep. */
  14. #endif
  15.  
  16. #include <LIBlib.h>
  17. // #include <LIBend.h>
  18.  
  19. #include <stdio.h>        /* For sprintf. */
  20. #include <string.h>        /* For strlen. */
  21. #include <time.h>
  22.  
  23. /*
  24.     Return the print string of the current date.
  25.  
  26.     See section 3.8.8 of the ANSI standard for a specification of the format.
  27.  
  28.     Surround the time in quotes if quote_flag is TRUE.
  29. */
  30.  
  31. /* The standard abbreviations for the months. */
  32. static char *monthname[] = {
  33.     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  34.     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  35. };
  36.  
  37. char *
  38. cvt_date(char * buffer, int buf_size, bool quote_flag)
  39. {
  40.     time_t        ltime;
  41.     struct tm *    t;
  42.     int            n;
  43.  
  44.     time(<ime);
  45.     t = localtime(<ime);
  46.  
  47.     n = sprintf(buffer, quote_flag ? "\"%3s %02d %d\"" : "%3s %02d %d",
  48.             monthname[t -> tm_mon], t -> tm_mday, 1900 + t -> tm_year);
  49.  
  50.     PERM_ASSERT(n < buf_size);
  51.     return buffer;
  52. }
  53.  
  54. /*
  55.     Return a print string of the current time.
  56.  
  57.     See section 3.8.8 of the ANSI standard for a specification of the format.
  58.  
  59.     Surround the date in quotes if quote_flag is TRUE.
  60. */
  61. char *
  62. cvt_time(char * buffer, int buf_size, bool quote_flag)
  63. {
  64.     time_t        ltime;
  65.     struct tm *    t;
  66.     int            n;
  67.  
  68.     time(<ime);
  69.     t = localtime(<ime);
  70.     n = sprintf(buffer, quote_flag ? "\"%02d:%02d:%02d\"" : "%02d:%02d:%02d",
  71.         t->tm_hour, t->tm_min, t->tm_sec);
  72.     
  73.     PERM_ASSERT(n < buf_size);
  74.     return buffer;
  75. }
  76.